package org.example.delaytimetask;

import java.util.concurrent.CountDownLatch;

/**
 * 高并发条件下，多消费者会取到同一个订单号
 * @author chaigq
 * @version 1.0
 * @date 2021/8/31 2:32 下午
 */
public class RedisTaskThread {

    private static final int threadNum = 10;
    private static CountDownLatch cdl = new CountDownLatch(threadNum);

    static class DelayMessage implements Runnable{

        @Override
        public void run() {
            try {
                cdl.await();
            } catch (InterruptedException e) {
                e.printStackTrace();

            }
            RedisTask appTest = new RedisTask();
            appTest.consumerDelayMessage();
        }
    }

    public static void main(String[] args) {

        RedisTask appTest =new RedisTask();

        appTest.producDelayMessage();

        for(int i=0;i<threadNum;i++){
            new Thread(new DelayMessage()).start();
            cdl.countDown();
        }
    }
}
